/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package neuronalenetzeelearning.view.controlpanel;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import neuronalenetzeelearning.model.Graph;
import neuronalenetzeelearning.model.Matrix;
import neuronalenetzeelearning.view.gui.GUI;
import neuronalenetzeelearning.view.mathoutput.MathOutputComponent;

/**
 *
 * @author henning
 */
public class MatrixOutputPanel extends GraphPanelProperty {
    JSpinner StepSpinner;
    JPanel matrixPanel;
    LinkedList<Matrix>matrixList = new LinkedList<Matrix>();

    public MatrixOutputPanel(GraphPanelProperty stepPanel){
        super();
        this.setBackground(background);
        this.setLayout(grid);
        this.setBorder(javax.swing.BorderFactory.createTitledBorder("Option: Das Netz maximal n-Schritte lernen lassen (n <= 20)"));

        //Set the look and feel
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (stepPanel instanceof NStepPanel){
            NStepPanel nStep = (NStepPanel) stepPanel;
            this.matrixList.addAll(nStep.getMatrixList());
        }
        if (stepPanel instanceof PassPanel){
            PassPanel passStep = (PassPanel) stepPanel;
            this.matrixList.addAll(passStep.getMatrixList());
        }
        if (stepPanel instanceof StepwisePanel){
            StepwisePanel stepwiseStep = (StepwisePanel) stepPanel;
            this.matrixList.addAll(stepwiseStep.getMatrixList());
        }

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.gridheight = 1;
        constraints.gridx = 1;
        constraints.gridy = 1;

        JLabel bord = new JLabel("------------------------------------------------------------------------------------------------------------------");
        add(bord, constraints);

        constraints.gridwidth = GridBagConstraints.RELATIVE;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridheight = 1;
        constraints.gridx = 1;
        constraints.gridy = 2;

        matrix = new MathOutputComponent(graph.getWeightMatrix());
        matrixPanel = new JPanel();
        matrixPanel.setBackground(background);
        matrixPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Gewichtsmatrix"));
        matrixPanel.add(matrix);
        this.add(matrixPanel, constraints);

        constraints.gridwidth = GridBagConstraints.RELATIVE;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridheight = 1;
        constraints.gridx = 2;
        constraints.gridy = 2;

        StepSpinner = new JSpinner();
        StepSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, this.matrixList.size(), 1));
        StepSpinner.setBackground(background);
        this.add(StepSpinner, constraints);

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridx = 1;
        constraints.gridy = 3;

        navigation.add(previous, constraints);
        navigation.add(getHelpButton(), constraints);
        this.add(navigation, constraints);

        this.setVisible(true);
    }
    public static void main(String[]args){
        JFrame test = new JFrame();
        test.setPreferredSize(new Dimension(800, 800));
        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Graph graph = new Graph();
        test.add(new MatrixOutputPanel(new NStepPanel()));
        test.pack();
        test.setVisible(true);
    }


}
